﻿using System.Runtime.InteropServices;

namespace Ast.Core.Pe.Definitions
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct DosHeader
    {
        public static readonly ushort MzSignature = 0x5A4D;

        // DOS .EXE header
        public ushort Magic;

        public short BytesOnLastPageOfFile;

        public ushort PagesInFile;

        public ushort Relocations;

        public ushort HeaderParagraphs;

        public ushort MinimumExtraParagraphs;

        public ushort MaximumExtraParagraphs;

        public ushort InitialStackSegment;

        public ushort InitialStackPointer;

        public ushort Checksum;

        public ushort InitialInstructionPointer;

        public ushort InitialCodeSegment;

        public ushort RelocationTableOffset;

        public short OverlayNumber;

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public ushort[] Reserved;

        public ushort OemID;

        public ushort OemInfo;

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public ushort[] MoreReserved;

        public uint NewExeHeaderOffset;

        public bool IsValid
        {
            get { return this.Magic == MzSignature; }
        }
    }
}